package com.hnucm.c202001020214.fragment;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;

import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.hnucm.c202001020214.Account;
import com.hnucm.c202001020214.GlideEngine;
import com.hnucm.c202001020214.R;
import com.hnucm.c202001020214.ShoppingCart;
import com.hnucm.c202001020214.YiBan;
import com.luck.picture.lib.basic.PictureSelector;
import com.luck.picture.lib.config.SelectMimeType;
import com.luck.picture.lib.entity.LocalMedia;
import com.luck.picture.lib.interfaces.OnResultCallbackListener;

import java.io.File;
import java.util.ArrayList;


public class UserCenter extends Fragment {

    ConstraintLayout yiBan ;

    ImageView imageView9;

    TextView textView,textView4;
    View view;
    ImageView imageView3,imageView;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view =inflater.inflate(R.layout.fragment_wd, container, false);
        setView(view);



        return view;


    }


    public void setView(View view) {
        imageView3 = view.findViewById(R.id.imageView3);
        imageView3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getActivity(), Account.class);
                startActivity(intent);
            }
        });

        imageView = view.findViewById(R.id.imageView);
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                //获取相册
                PictureSelector.create(UserCenter.this)
                        .openGallery(SelectMimeType.ofImage())
                        .setImageEngine(GlideEngine.createGlideEngine())
                        .forResult(new OnResultCallbackListener<LocalMedia>() {
                            @Override
                            public void onResult(ArrayList<LocalMedia> result) {

                                Glide.with(UserCenter.this)
                                        .load(Uri.fromFile(new File(result.get(0).getRealPath())))
                                        .into(imageView);

                            }

                            @Override
                            public void onCancel() {

                            }
                        });

            }
        });

        yiBan = view.findViewById(R.id.yiBan);
        yiBan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getActivity(), YiBan.class);
                startActivity(intent);
            }
        });


        imageView9 = view.findViewById(R.id.imageView9);
        imageView9.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getActivity(), ShoppingCart.class);
                startActivity(intent);
            }
        });
    }


}